package com.shujia.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class MySQLTool {
    private static Properties prop;
    private static Connection conn;
    private MySQLTool(){}

    public static Connection getConnection(){
        try {
            //创建Properties对象
            prop = new Properties();
            prop.load(new BufferedReader(new FileReader("D:\\projects\\IdeaProjects\\bigdata32\\redis\\src\\main\\resources\\mysql.properties")));
            String url = prop.getProperty("url");
            String username = prop.getProperty("username");
            String password = prop.getProperty("password");

            // 注册驱动，告诉java程序我们要链接什么数据库
            Class.forName("com.mysql.jdbc.Driver");

            conn = DriverManager.getConnection(url, username, password);
        }catch (Exception e){
            e.printStackTrace();
        }

        return conn;
    }
}
